<template>
    <div id="FavrioteLive">
        <h1 class="e_h1">我的收藏</h1>
        <div class="Favriote clearfix" v-for="v in phoArr5" :key="v.id">
            <a :href="v.vedio"> <img :src="v.img" alt="" class="e_img"></a>
            <div class="c_hot1">
                <p class="c_p4">{{ v.title }}</p>
                <p class="c_p5">{{ v.content }}</p>
            </div>
            <div class="e_zan">
                <i class="iconfont icon-Favorite2  c_xing" :class="{ 'liked': v.liked, 'not-liked': !v.liked }"
                    @click="v.liked ? handleUnlike(v.id) : handleLike(v.id)"></i>
                <span class="c_cllo">已收藏<i>{{ v.count }}</i>人</span>
            </div>
        </div>

    </div>
</template>
  
<script>
import axios from 'axios';
export default {

    data() {
        return {
            phoArr5: [],
        }
    },
    methods: {
        handleLike(v) {
            let like = this.phoArr5.find(item => item.v === v);
            if (like) {
                like.liked = true;
                like.count++;
            }
        },
        handleUnlike(v) {
            let like = this.phoArr5.find(item => item.v === v);
            if (like) {
                like.liked = false;
                like.count--;
            }
            axios({
                url: '/dbdata/phoArr5/' + v,
                method: 'delete',
            })
                .then(() => {
                    return axios({
                        url: '/dbdata/phoArr5/',
                        method: 'get',
                    });
                })
                .then(({ data }) => {
                    this.phoArr5 = data;
                    this.$message.error('取消收藏');
                })
        },
    },
    mounted() {
        axios({
            url: '/dbdata/phoArr5/',
            method: 'get',
        }).then(() => {
            return axios({
                url: '/dbdata/phoArr5/',
                method: 'get',
            });
        })
            .then(({ data }) => {
                this.phoArr5 = data;
                // this.count++;
                console.log(data)
            })
    }
}
</script>
<style lang="less">
#FavrioteLive {
    width: 1000px;
    margin: auto;
    position: relative;

    .Favriote:hover .c_hot1 {
        display: block;
    }

    .e_h1 {
        font-size: 30px;
        font-family: "楷体";
        color: #777676;
    }

    .c_hot1 {
        position: absolute;
        display: none;
        margin-top: -120px;
        width: 300px;
        height: 116px;
        margin-left: 20px;
        background-color: rgba(119, 78, 2, 0.5);


        .c_p4 {
            font-size: 14px;
            line-height: 20px;
            font-weight: bold;
            text-align: center;
            color: white;
        }

        .c_p5 {
            margin: auto;
            // text-align: left;
            color: white;
            width: 250px;
            font-size: 13px;
        }
    }

    .liked {
        color: red;
    }

    .Favriote {
        text-align: left;
        float: left;
    }

    .clearfix:after {
        visibility: hidden;
        display: block;
        content: " ";
        clear: both;

    }

    .not-liked {
        color: black;
    }

    .e_img {
        width: 300px;
        height: 200px;
        margin-left: 20px;
        margin-top: 20px;
    }

    .e_zan {
        margin-left: 100px;
    }

    .e_img1 {
        width: 300px;
        height: 200px;
        margin-left: 20px;
        margin-top: 20px;
    }
}
</style>